<template>
	<view class="main-container">
		<!--  头部搜索栏 -->
		<!-- 	<view class="head">
			<view class="search_view">
				<input class="search" v-model="searchValue" placeholder="请输入关键字搜索" />
				<image src="http://113.142.144.25:9301/statics/appimg/icon_search_btn_new.png" 
					style="height: 30rpx;width:30rpx;padding: 20rpx;" @click="searchPolicy()"></image>
			</view>
		</view> -->

		<!--导航栏-->
		<!-- <orderTabBar :tabList="tabList" @clickTabBar="clickTabBar" class="tab-bar" :show-line="true" /> -->
		<!--订单列表-->
		<u-list @scrolltolower="scrollToLower">
			<view class="policy_list">
				<u-list-item class="policy_item" v-for="(item, index) in orderList" :key="index">
					<view style="width: 100%" @click="policyDetail(item)">
						<view>
							<text class="policy_title">{{ item.name }}</text>
						</view>
						<view v-if="item.createTime">
							<text class="publicTime">发布时间：{{ item.createTime }}</text>
						</view>
						<view v-else>
							<text class="publicTime">发布时间：未知</text>
						</view>
						<view class="devideline"></view>
					</view>
				</u-list-item>
				<view class="no-data" v-if="orderList.length == 0" @click="getOrderList()">
					<image src="https://file.genepre.com/wechat/nomsg5_new.png" mode="aspectFit" class="no-data-img"></image>
					{{ noData }}
				</view>
			</view>
		</u-list>
		<!-- <scroll-view class="policy_list" scroll-y="true" :style="'height:97%'" enable-flex @scrolltolower="scrollToLower()" @scrolltoupper="updateOrderInfo()">
			<view class="policy_item" v-for="(item, index) in orderList" :key="index" @click="policyDetail(orderList[index])"> -->
		<!-- <view style="width: 100%;" v-show="item.coverImage">
					<view style="width: 60%; float:left">
						<view>
							<rich-text class="policy_title" :nodes="item.title"></rich-text> 
						</view>
						<view>
							<text class="publicTime">{{item.publishTime}}</text>
						</view>
					</view>
					<view style="width: 40%; float:left">
						<image style="height:150rpx;width: 260rpx; margin-top: 20rpx; margin-right: 20rpx; border-radius: 5rpx; float: left;" :src="item.coverImage"></image>
					</view>
					<view class="devideline"></view>
				</view> -->
		<!-- <view style="width: 100%">
					<view>
						<text class="policy_title">{{ item.name }}</text>
					</view>
					<view v-if="item.createTime">
						<text class="publicTime">发布时间：{{ item.createTime }}</text>
					</view>
					<view v-else>
						<text class="publicTime">发布时间：未知</text>
					</view>
					<view class="devideline"></view>
				</view>
			</view>

			<view class="no-data" v-if="orderList.length == 0" @click="getOrderList()">
				<image src="https://file.genepre.com/wechat/nomsg5_new.png" mode="aspectFit" class="no-data-img"></image>
				{{ noData }}
			</view>
		</scroll-view> -->
	</view>
</template>

<script>
import env from '../../utils/env';
import orderTabBar from '@/wxcomponents/tab_bar.vue';
import * as article from '@/api/article.js';
import * as codeList from '@/utils/code.js';
export default {
	components: {
		orderTabBar
	},
	data() {
		return {
			showPage: false,
			// 订单列表tab项
			tabList: [
				{
					status: '',
					title: '全部'
				},
				{
					status: '1',
					title: '国家政策'
				},
				{
					status: '2',
					title: '省级政策'
				},
				{
					status: '3',
					title: '市级政策'
				}
			],
			// 当前选择tab项
			currentIndex: 0,
			// 当前查询状态
			currentStatus: '',
			// 订单列表高度
			orderHeight: 0,
			// 是否还有更多数据
			noMoreData: {},
			// 订单列表
			orderList: [],
			// 页码数组
			query: {
				pageNum: 1,
				// 每页请求数
				pageSize: 10
			},
			policylevel: '',
			searchValue: '',
			noData: '加载中',
			total: 0
		};
	},
	onShow() {
		// let _this = this
		// _this.getOrderList()
	},
	mounted() {
		let _this = this;
		// const query = uni.createSelectorQuery().in(this);
		// query.select('.tab-bar').boundingClientRect(data => {
		//   _this.tabHeight = data.height
		//   _this.orderHeight = _this.windowHeight-5
		// }).exec();
		uni.showLoading({
			title: '加载中。。。'
		});
		this.getOrderList();
	},
	methods: {
		// tab切换
		clickTabBar(index, status) {
			this.currentIndex = index;
			this.currentStatus = status;
			this.orderList = [];
			this.getOrderList();
		},
		// 加载订单列表
		getOrderList() {
			uni.showLoading({
				title: '加载中。。。'
			});
			this.noData = '加载中。。。';
			article.getArticle(this.query).then((res) => {
				if ((res.errMsg = 'request:fail')) {
					this.noData = '暂无数据，点击重试';
				}
				res.rows.forEach((v) => {
					if (v.coverImage != null) {
						v.coverImage = `${env.imgUrl}` + v.coverImage;
					}
					this.orderList.push(v);
				});
				this.total = res.total;
				uni.hideLoading({});
				if (this.orderList.length == 0) {
					this.noData = '暂无数据，点击重试';
				}
			});
			// if(this.orderList.length == 0){
			// 	this.noData = '暂无数据，点击重试'
			// }
		},
		// 更新order
		updateOrderInfo(index) {
			let _this = this;
			this.query.pageNum = 1;
			this.orderList = [];
			_this.getOrderList();
		},
		// 滑到底部 加载更多
		scrollToLower() {
			if (this.orderList.length < this.total) {
				this.query.pageNum = this.query.pageNum + 1;
				this.getOrderList();
			} else {
				uni.showToast({
					icon: 'none',
					title: '没有更多数据'
				});
			}
		},
		policyDetail(item) {
			uni.navigateTo({
				url: '/subpages/pages/detail/policy_detail?id=' + item.id
				// url:'/pages/detail/policy_detail?id='+ item.id,
			});
		},
		searchPolicy() {
			var data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				searchvalue: this.searchValue,
				code: 'KJZC'
			};
			article.getArticleByKeyword(data).then((res) => {
				console.log(res);
				this.orderList = res.rows;
			});
		}
	},
	computed: {}
};
</script>

<style scoped>
.main-container {
	width: 100vw;
	height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
	background-color: #e6e6e6;
}

.main-container .tab-bar {
	width: 93%;
	border-radius: 15rpx;
}

.main-container .order-lists {
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
}

.head {
	display: flex;
	width: 93vw;
	margin: 20rpx auto;
	height: 70rpx;
	border-radius: 30rpx;
	background-color: #fff;
	text-align: center;
}

.search_view {
	margin: 0 auto;
}

.search {
	height: 40rpx;
	padding-top: 15rpx;
	font-size: 25rpx;
	float: left;
}

.no-data {
	width: 100%;
	height: 300rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	font-size: 32rpx;
	margin-top: 100rpx;
}

.no-data .no-data-img {
	width: 300rpx;
	height: 268rpx;
}

.policy_list {
	width: 93%;
	margin: 20rpx 35rpx;
	height: 95vh;
	background-color: #fff;
	border-radius: 15rpx;
}

::v-deep .u-list-item {
	/* height: 80rpx; */
	padding-left: 20rpx;
	background-color: #fff;
}

.policy_title {
	display: -webkit-box;
	width: 95%;
	margin-top: 20rpx;
	font-size: 28rpx;
	overflow: hidden;
	word-break: break-all; /* break-all(允许在单词内换行。) */
	text-overflow: ellipsis; /* 超出部分省略号 */
	display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
	-webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
	-webkit-line-clamp: 1; /** 显示的行数 **/
}

.publicTime {
	float: left;
	font-size: 26rpx;
	color: #a1a1a1;
	margin-top: 15rpx;
}

.devideline {
	float: left;
	height: 0.3rpx;
	width: 100%;
	background-color: #eeeeee;
	margin-top: 15rpx;
	margin-bottom: 15rpx;
}
</style>
